package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.dto.StudentQueryDto;
import com.itheima.pojo.Student;
import com.itheima.vo.SexVo;
import com.itheima.vo.StudentVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface StudentMapper {


    Page<StudentVo> StudentQuery(StudentQueryDto dto);

    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    void insert(Student student);

    void update(Student student);

    @Delete("delete from student where id = #{id}")
    void delete(Integer id);

    @Delete("delete from student where clazz_id = #{id}")
    void deleteByClazzId(Integer id);

    @Select("select count(*) from student where clazz_id = #{id}")
    Integer countByClazzId(Integer id);

    @Update("update student set violation_score = violation_score + #{score},violation_count=violation_count+1 where id = #{id}")
    void violation(Integer id, Integer score);


    List<SexVo> studentEducationData();


    /*按班级统计人数*/
    @Select("select clazz_id as name,count(id) as value from student group by clazz_id")
    List<SexVo> countData();

}
